import java.util.Scanner;

public class ThreadDemo14 {

    volatile public static int flag = 0;
    public static void main(String[] args) {
        Thread t1 = new Thread(()-> {
            while (flag == 0) {
                //System.out.println(flag);
            }
            System.out.println("循环结束");
        });

        Thread t2 = new Thread(()-> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入一个值");
            flag = scanner.nextInt();

        });

        t1.start();
        t2.start();
    }
}//预期结果，通过flag == 0作为条件循环，初始情况1将进入循环
//t2通过控制台输入一个整数，一旦用户输入一个非0的树，从此t1的循环就会结束
//从而t1线程就会退出


